package com.bml.architect.consumer;

import com.bml.architect.DemoService;
import com.bml.architect.consumer.web.MyConsumerIntercept;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class DemoServiceConsumer implements WebMvcConfigurer {


    @Autowired
    private HandlerInterceptor myConsumerIntercept;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myConsumerIntercept);
    }

    @Reference(version = "default")
    private DemoService demoService;

    public static void main(String[] args) {


        ConfigurableApplicationContext ca = SpringApplication.run(DemoServiceConsumer.class);

        DemoService demoServiec = ca.getBean(DemoService.class);
        for (int i = 0; i < 5; i++) {
            System.out.println(demoServiec.sayHello("李四"));
        }
    }
}
